<?php
namespace Admin\Controller;
use Think\Controller;
class SiteController extends myController{
	public function index(){
		$model=D('Site');
		$arr=$model->find(1);//本来就是取出一条数据
		$this->assign('arr',$arr);
		$this->display('index');
	}
	//编辑网站信息
	public function edit(){	
		if(IS_POST){
			$model=D('Site');
			$id=(int)$_GET['id'];
			if($data=$model->create()){
				$data['id']=$id;
				//上传文件								
				if(empty($_FILES['logo']['name'])){
					unset($data['logo']);
				}else{		
		  $config = array(    
				'maxSize'    =>    3145728,  
		  		'rootPath'   =>    './Public/Uploads/',				   
				  'saveName'   =>    array('uniqid',''),  
				  'exts'       =>    array('jpg', 'gif', 'png', 'jpeg'),   
				  'autoSub'    =>    true,   
				  'subName'    =>    array('date','Ymd'),				
		);
		$upload=new \Think\Upload($config);//实例化上传类
		//上传文件
		$info=$upload->uploadOne($_FILES['logo']);	
		if(!$info) {			
			// 上传错误提示错误信息        
			$this->error($upload->getError());   
		 }else{
		 	// 上传成功 获取上传文件信息 		 	 
		 	 $data['logo']=$info['savepath'].$info['savename']; 	 	 
		  }										
	   }
			if($model->save($data)){				
				$this->success('保存成功',U('index'),1);
				exit;
			}else{
				$this->error('保存失败',U('index'),1);
			}
		}else{
			$this->error('创建失败');
		}
	}
  }
  
}